var app = angular.module("myApp");
app.controller("inController", function ($http, $scope) {
    //获取库存信息列表
    var baseUrl = 'http://localhost:8089'
    $http({
        method: 'GET',
        url: baseUrl + '/wms/app/stock/getStock'
    }).then(function successCallback(response) {
        if (response.data.code == 200) {
            $scope.stock = response.data.data
            console.debug(stock);
        } else {
            alert(response.data.errorMsg);
        }

    }, function errorCallback() {
        alert("请求失败");
    })

    //根据sku查询商品库存
    $scope.getStockBySku = function (sku) {
        $http({
            method: 'GET',
            url: baseUrl + '/wms/app/stock/getStockBySku?sku=' + sku
        }).then(function successCallback(response) {
            if (response.data.code == 200) {
                $scope.stock = response.data.data;
            } else {
                alert(response.data.errorMsg);
            }
        }, function errorCallback() {
            alert("服务端异常")
        })
    }

    //回显sku
    $scope.inStock = function (sku) {
        $scope.in_sku = sku;
    }

    //添加入库详情
    $scope.inToStock = function () {
        $http({
            method: 'POST',
            url: baseUrl + '/wms/app/stock/inToStock',
            data: $("#inStockForm").serialize(),
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            }
        }).then(function successCallback(response) {
            if (response.data.code == 200){
                alert("入库成功")
            }else {
                alert("入库失败")
            }
        }, function errorCallback() {
            alert("请求失败")
        })

    }

})